Skip to main content
Version: 1.0.1

OpenCV

ImageTransformer

from synapse.ml.opencv import *
from pyspark.sql.types import FloatType

# images = (spark.read.format("image")
# .option("dropInvalid", True)
# .load("wasbs://publicwasb@mmlspark.blob.core.windows.net/explainers/images/david-lusvardi-dWcUncxocQY-unsplash.jpg"))

it = (ImageTransformer(inputCol="image", outputCol="features")
.resize(224, True)
.centerCrop(height=224, width=224)
.normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], color_scale_factor = 1/255)
.setTensorElementType(FloatType()))

# it.transform(images).show()
Python API: ImageTransformerScala API: ImageTransformerSource: ImageTransformer

ImageSetAugmenter

from synapse.ml.opencv import *

# images = (spark.read.format("image")
# .option("dropInvalid", True)
# .load("wasbs://publicwasb@mmlspark.blob.core.windows.net/explainers/images/david-lusvardi-dWcUncxocQY-unsplash.jpg"))

isa = (ImageSetAugmenter()
.setInputCol("image")
.setOutputCol("augmented")
.setFlipLeftRight(True)
.setFlipUpDown(True))

# it.transform(images).show()
Python API: ImageSetAugmenterScala API: ImageSetAugmenterSource: ImageSetAugmenter